﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Learnive.Models;

namespace Learnive.Controllers
{
    public class VakjeController : Controller
    {
        private LearniveContext db = new LearniveContext();

        //
        // GET: /Vakje/

        public ActionResult Index()
        {
            return View(db.Vakjes.ToList());
        }

        [HttpPost]
        public ActionResult Details(HttpPostedFileBase file)
        {

            if (file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path = Path.Combine(Server.MapPath("~/Content/upload"), fileName);
                file.SaveAs(path);
            }
            return RedirectToAction("Details");
        }
        //
        // GET: /Vakje/Details/5

        
        public ActionResult Details(int id = 0)
        {
            Vakje vakje = db.Vakjes.Find(id);
            if (vakje == null)
            {
                return HttpNotFound();
            }
            return View(vakje);
        }

        //
        // GET: /Vakje/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Vakje/Create

        
        [HttpPost]
        public ActionResult Create(Vakje vakje)
        {
            if (ModelState.IsValid)
            {
                db.Vakjes.Add(vakje);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(vakje);
        }

        //
        // GET: /Vakje/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Vakje vakje = db.Vakjes.Find(id);
            if (vakje == null)
            {
                return HttpNotFound();
            }
            return View(vakje);
        }

        //
        // POST: /Vakje/Edit/5

        [HttpPost]
        public ActionResult Edit(Vakje vakje)
        {
            if (ModelState.IsValid)
            {
                db.Entry(vakje).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(vakje);
        }

        //
        // GET: /Vakje/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Vakje vakje = db.Vakjes.Find(id);
            if (vakje == null)
            {
                return HttpNotFound();
            }
            return View(vakje);
        }

        //
        // POST: /Vakje/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Vakje vakje = db.Vakjes.Find(id);
            db.Vakjes.Remove(vakje);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}